{% load humanize mathfilters %}

<div class="row">
                            <div class="col-12 table-responsive">
                                <table id="scroll-horizontal-datatable"
                                       class="table table-hover table-bordered table-centered table-condensed table-sm w-100 m-0 nowrap">
                                    <thead>
                                    <tr class="text-center bg-dragula">
                                        <th style="width: 22%">납부기일</th>
                                        <th style="width: 18%">구분</th>
                                        <th style="width: 20%">납부약정금액</th>
                                        <th style="width: 20%">수납금액</th>
                                        <th style="width: 20%">미(과오)납</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for po in payment_orders %}
                                        <tr>
                                            <td class="text-center">
                                                {% if po.pay_code == 1 %}
                                                    {{ this_contract.contractor.contract_date|date:"Y-m-d" }}
                                                {% elif po.pay_code == 2 %}
                                                    {{ second_pay|date:"Y-m-d" }}
                                                {% else %}
                                                    {{ po.pay_due_date|date:"Y-m-d"|default:"0000-00-00" }}
                                                {% endif %}
                                            </td>
                                            <td class="text-center">{{ po.pay_name }}</td>

                                            {% with payment_due=payment_list.pop pay_sum_by_order=pay_sum_by_order_list.pop %}
                                                <td class="text-right">
                                                    {% if payment_due %}{{ payment_due|default:"-"|intcomma }}{% else %}-{% endif %}
                                                </td>
                                                <td class="text-right">
                                                    {% ifequal pay_sum_by_order 0 %}-{% else %}
                                                        {{ pay_sum_by_order|intcomma|default:"-" }}{% endifequal %}
                                                </td>
                                                <td class="text-right {% if pay_sum_by_order > payment_due %}text-primary{% elif pay_sum_by_order < payment_due %}text-danger{% endif %}">
                                                    {% if po.pay_code <= 2 or po.pay_due_date %}
                                                        {% ifequal pay_sum_by_order payment_due %}-{% else %}
                                                        {{ pay_sum_by_order|sub:payment_due|intcomma|default:"-" }}{% endifequal %}
                                                    {% else %}-{% endif %}
                                                </td>
                                            {% endwith %}
                                        </tr>
                                    {% endfor %}
                                    <tr class="bg-light">
                                        <th class="text-center bg-secondary-lighten">합계</th>
                                        <th></th>
                                        <th class="text-right">{{ this_price|default:"-"|intcomma }}</th>
                                        <th class="text-right">{{ payment_sum.income__sum|default:"-"|intcomma }}</th>
                                        <th class="text-right text-{% if unpaid < 0 %}danger{% else %}primary{% endif %}">{{ unpaid|default:"-"|intcomma }}</th>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
